clear all
set more off

cd "C:\Dropbox\Average_target_survey\replication_folder\workfiles"

use step003, clear

***collapse days when the sample size is small
gen start_day2=start_day1
recode start_day2 30/32=29
recode start_day2 33/51=30
recode start_day2 17/26=26

*** Have you heard any news about the Fed
gen QJH3_Yes=(QJH3==2) if QJH3~=. 
* tab start_day1 QJH3 [aw=weight], row nofreq

*** How many pieces of news about the Fed did you heard
tab start_day1 QJH4  [aw=weight] , row nofreq  
forvalues i=1(1)5 {
	gen QJH4_`i'=(QJH4==`i') if QJH4~=.
}
*** Where did you hear the news
* tabstat QJH5_1 QJH5_2 QJH5_3 QJH5_4 QJH5_5 QJH5_6 QJH5_7 QJH5_8 QJH5_9 [aw=weight], by(start_day1) format("%3.2f")

*** When did you hear the news
* tab start_day1 QJH6  [aw=weight] , row nofreq
forvalues i=0(1)6 {
	gen QJH6_`i'=(QJH6==`i') if QJH6~=.
}

*** What did you hear about the Fed
tabstat QJH7_1 QJH7_2 QJH7_3 QJH7_4 QJH7_5 QJH7_6 [aw=weight], by(start_day1) format("%3.2f")

*** Who did you hear about the Fed
tabstat QJH8_1 QJH8_2 QJH8_3 QJH8_4 QJH8_5 QJH8_6 [aw=weight], by(start_day1) format("%3.2f")

*** What is the Fed doing (objective)
tabstat QJH9_1 QJH9_2 QJH9_3 QJH9_4 QJH9_5 QJH9_6 QJH9_7 QJH9_8 QJH9_9 [aw=weight], by(start_day1) format("%3.2f")

*** What does Fed in terms of prices?
tabstat QJH10_1 QJH10_2 QJH10_3 QJH10_4 QJH10_5 QJH10_6 QJH10_7 [aw=weight], by(start_day1) format("%3.2f")

tempname 1
postfile `1'  str50 variable ///
	str50 E_statistic ///
	str12 E_aug26 ///
	str12 E_aug27 ///
	str12 E_aug28 ///
	str12 E_aug29 ///
	str12 E_aug30 ///
	using "C:\Dropbox\Average_target_survey\replication_folder\outregs\Table05.dta", replace every(1)
	
*** create dummy variables for each day	
foreach var in 26 27 28 29 30 {	
	gen aug`var'=(start_day2==`var')
	gen _aug`var'=aug`var'*sqrt(weight)
}	

gen QJH10_A=0
replace QJH10_A=1 if QJH10_6==1
replace QJH10_A=1 if QJH10_7==1
replace QJH10_A=1 if QJH10_6==.
	
foreach var in ///
	QJH9_1 QJH9_2 QJH9_3 QJH9_4 QJH9_5 QJH9_6 QJH9_7 QJH9_8 QJH9_9 ///  What is the Fed doing (objective)
	QJH10_1 QJH10_2 QJH10_3 QJH10_4 QJH10_5 QJH10_6 QJH10_7 QJH10_A /// What does Fed in terms of prices?
				{
		
			    
	
			***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			*** raw mean
			***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			
			reg `var' aug26 aug27 aug28 aug29 aug30 [aw=weight], robust nocons
			test aug26 = aug27
			local p1=r(p)
			test aug26 = aug28
			local p2=r(p)
			test aug26 = aug29
			local p3=r(p)			
			test aug26 = aug30
			local p4=r(p)			
			
			local M26_mean=string(_b[aug26],"%4.2f")
			local M27_mean=string(_b[aug27],"%4.2f")
			local M28_mean=string(_b[aug28],"%4.2f")
			local M29_mean=string(_b[aug29],"%4.2f")
			local M30_mean=string(_b[aug30],"%4.2f")

			if abs(`p1')<0.1 & `p1'~=. local M27_mean="`M27_mean'" + "*"
			if abs(`p2')<0.1 & `p2'~=. local M28_mean="`M28_mean'" + "*"
			if abs(`p3')<0.1 & `p3'~=. local M29_mean="`M29_mean'" + "*"
			if abs(`p4')<0.1 & `p4'~=. local M30_mean="`M30_mean'" + "*"
			
			if abs(`p1')<0.05 & `p1'~=. local M27_mean="`M27_mean'" + "*"
			if abs(`p2')<0.05 & `p2'~=. local M28_mean="`M28_mean'" + "*"
			if abs(`p3')<0.05 & `p3'~=. local M29_mean="`M29_mean'" + "*"
			if abs(`p4')<0.05 & `p4'~=. local M30_mean="`M30_mean'" + "*"
			
			if abs(`p1')<0.01 & `p1'~=. local M27_mean="`M27_mean'" + "*"
			if abs(`p2')<0.01 & `p2'~=. local M28_mean="`M28_mean'" + "*"
			if abs(`p3')<0.01 & `p3'~=. local M29_mean="`M29_mean'" + "*"				
			if abs(`p4')<0.01 & `p4'~=. local M30_mean="`M30_mean'" + "*"				
			
			***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			*** post results
			***~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
			post `1' ("`var'") ("raw mean")	("`M26_mean'") ("`M27_mean'") ("`M28_mean'")  ("`M29_mean'") ("`M30_mean'")   
			if "`var'" == "QJH3_Yes" | "`var'" == "QJH4_1" | "`var'" == "QJH5_9" | "`var'" == "QJH6_6" | "`var'" == "QJH7_6" | "`var'" == "QJH8_6" | "`var'" == "QJH9_9" | "`var'" == "QJH10_A"{
				tab aug26 if `var' != . & aug26 == 1
				local n_aug26=r(N)
				tab aug27 if `var' != . & aug27 == 1
				local n_aug27=r(N)
				tab aug28 if `var' != . & aug28 == 1
				local n_aug28=r(N)
				tab aug29 if `var' != . & aug29 == 1
				local n_aug29=r(N)
				tab aug30 if `var' != . & aug30 == 1
				local n_aug30=r(N)

				post `1' ("`var'") ("N obs.") ("`n_aug26'") ("`n_aug27'") ("`n_aug28'") ("`n_aug29'") ("`n_aug30'")
			}

}

postclose `1'
